/*
 * Sketch_oct31b_tds.hpp
 * 定义 SEN0244 gravity TDS Sensor数据引脚
 * 这是一款arduino兼容的TDS传感器，用于测量水的TDS值，TDS数值可反应水的洁净程度，可应用于生活用水、水培等领域的水质检测。
 * TDS (Total Dissolved Solids)，中文名：总溶解固体，又称溶解性固体总量，表明1升水中溶有多少毫克溶解性固体。
 * 一般来说，TDS值越高，表示水中含有的溶解物越多，水就越不洁净。因此，TDS值的大小，可作为反映水的洁净程度的依据之一。
 * https://ic-item.jd.com/10078072381329.html
 * PLUGGED GPIO12 = D6
 */
#ifndef SKETCH_OCT31B_TDS_H
#define SKETCH_OCT31B_TDS_H
#include "Arduino.h"
/****************************************SEN0244 part****************************************/
class Sketch_oct31b_tds {
private:
  long VREF = 5.0;
  unsigned int SCOUNT = 30;
  int ONE_WIRE_BUS_PIN = 12;  // 定义SEN0244 gravity TDS Sensor数据引脚, PLUGGED GPIO12 = D6
  int analogBuffer[30];   // store the analog value in the array, read from ADC
  int analogBufferTemp[30];
  int analogBufferIndex = 0, copyIndex = 0;
  float averageVoltage = 0, tdsValue = 0, temperature = 25;
  int tdsTimeInterval = 3 * 1000;
  unsigned long cal_delayStart = 0;  // the time tds delay started
  /**
    * 功能描述：读取TDS设备编号
    */
  int getMedianNum(int bArray[], int iFilterLen);

  String loadData();
public:
  String str_tdsNumber;
  float ds18b20Temperature = 0;
  // ----- Constructor -----
  Sketch_oct31b_tds();
  Sketch_oct31b_tds(int sensorPin);
  ~Sketch_oct31b_tds();

  /**
    * 功能描述：初始化TDS浑浊探测棒
    */
  void initSEN0244DevManager();

  /**
    * 功能描述：读取TDS浑浊探测棒
    */
  void loadTDSAPI(long _interval);

  int getPin();

  void setDs18b20Temperature(float ds18b20Temperature);

  String getTds();
};
#endif